﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


using System;
using System.Collections.Generic;
using Tesla.Graphics;

namespace Tesla.Content.Loaders {
    /// <summary>
    /// External writer that takes in a number of Materials to be serialized to
    /// a single or multiple TEM script file.
    /// </summary>
    public sealed class MaterialExternalWriter : ExternalWriter<Material> {
        private bool _writeMultipleScripts;
        private List<Material> _materials;

        /// <summary>
        /// Gets or sets if the writer should serialize all materials
        /// to a single TEM file, or each instance to its own unique TEM file. Default
        /// is false (write to a single TEM file).
        /// </summary>
        public bool WriteMultipleScripts {
            get {
                return _writeMultipleScripts;
            }
            set {
                _writeMultipleScripts = value;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MaterialExternalWriter"/> class.
        /// </summary>
        public MaterialExternalWriter() 
            : base("material", String.Empty) {
                _materials = new List<Material>();
                _writeMultipleScripts = false;
        }

        /// <summary>
        /// Called when the writer is initialized by the savable writer, when it is registered with the savable
        /// writer.
        /// </summary>
        protected override void OnInitialize() {
            _materials.Clear();
        }

        /// <summary>
        /// Writes the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="savable">The savable.</param>
        /// <returns></returns>
        public override ExternalReference Write(String name, Material savable) {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Cleans up any remaining resources and finishes writing external objects.
        /// </summary>
        public override void Flush() {
            _materials.Clear();
        }
    }
}
